#
# Makefile for Hi3716M Platform Application Project
#
# Created By:	Leo		Date: Aug-08-2012
# Modified By:	Leo		Date: Aug-08-2012
#


include cfg.mak

BASEDIR		:= $(shell pwd)
HISIDIR		:= $(BASEDIR)/hisisdk
DRVDIR		:= $(BASEDIR)/driverpackage
APPDIR		:= $(BASEDIR)/apps

HISILIBDIR	:= $(HISIDIR)/lib/static
DRVLIBDIR	:= $(DRVDIR)/lib
APPLIBDIR	:= $(APPDIR)/lib


OBJDIR		:= $(BASEDIR)/objs


BASEINC	:= \
	-I$(BASEDIR)/include \
	-I$(HISIDIR)/include \
	-I$(DRVDIR)/include \
	-I$(MIDDIR)/include \
	-I$(APPDIR)/include


DRVINC	:= $(BASEINC)
MIDINC	:= $(BASEINC)
APPINC	:= $(BASEINC)

HISILIB	:= \
	-leffect -lfreetype -lhi_charsetMgr -lhi_common -lhi_msp -lhi_pes -lhi_resampler -lhi_so \
	-lhi_subtitle -lhi_ttx -lhi_voip -lhigo -lhigoadp -ljpeg -ljpeg6b -lplayer -lpng -lpng14 \
	-lrtp -lsubdec -lz \
	-lpthread -lrt -lm -lmy_protocol -lstore_drv -l3045b -len -lalpum_MP9EE -lgbhw -lsubdec -lwlansta -lwpa_client -lwlanap \
	-lpanmidi
            

CROSS_COMPILE := arm-hisiv200-linux-
CFLAGS		:= -DITOP_VERSION=$(CFG_ITOP_VERSION) -fPIC -g -Os -c -Wall
CFLAGS		+=-march=armv7-a -mcpu=cortex-a9
CFLAGS		+= -D_GNU_SOURCE -ffunction-sections -fdata-sections -Wl,--gc-sections -fshort-wchar
#CFLAGS+= -DCHIP_TYPE_${CFG_HI_CHIP_TYPE} -DCFG_HI_SDK_VERSION=${CFG_HI_SDK_VERSION}

DFLAGS		:= -Os
LDFLAGS		:= -static

AR			:= $(CROSS_COMPILE)ar
AS			:= $(CROSS_COMPILE)as
GCC			:= $(CROSS_COMPILE)gcc
GPP			:= $(CROSS_COMPILE)c++
LD			:= $(CROSS_COMPILE)ld
NM			:= $(CROSS_COMPILE)nm
STRIP		:= $(CROSS_COMPILE)strip

MKCRAMFS	:= mkcramfs
MKJFFS2		:= mkfs.jffs2

export AR GCC GPP
export CFLAGS DFLAGS
export BASEDIR DRVDIR APPDIR OBJDIR HISIDIR 
export DRVINC APPINC DRVLIBDIR APPLIBDIR


OBJS	:= $(OBJDIR)/main.o
EXE	:= $(BASEDIR)/myApp

# KTV_SHIYOU_SYS
#NFSPATH	:= /media/store/tmp/nfshare/s2/
NFSPATH	:= /home/shiyou/Hisi3716C/bindBinUpdate/

all: drv app exe

exe:  $(OBJS)
	$(GPP) -g -o $(EXE) $(OBJS) -Wl,--start-group $(HISILIB) $(DRVLIB) $(APPLIB) -lpthread -lm -ldl -Wl,--end-group -L$(HISILIBDIR) -L$(DRVLIBDIR)
#	$(STRIP) $(EXE)
	# KTV_SHIYOU_SYS
	#-sudo chmod 777 $(EXE)
	#cp $(EXE) $(NFSPATH)SYSDRV
	# @cp -rvf $(EXE) $(NFSPATH)kalaka
	# @cp -rvf $(DRVLIBDIR)/libmy_protocol.so $(NFSPATH)
	#./tools/mkyaffs2image504 burn/app burn/app.yaffs 1 1
	#./tools/mkyaffs2image504 flashfile/e burn/e.yaffs 1 1

	@echo ""
	@date
	@echo ""
	@echo ""
	@echo "******************************************************"
	@echo "******************************************************"
	@echo ""
	@echo "                   Build Success !!!"
	@echo ""
	@echo "******************************************************"
	@echo "******************************************************"
	@echo ""
	@echo ""
			
prepare_dir:
	@mkdir -p $(DRVLIBDIR)
	@mkdir -p $(APPLIBDIR)
	@mkdir -p $(OBJDIR)


clean: drv_clean  app_clean
	rm -fr $(OBJDIR)
	rm -fr $(EXE)

include $(DRVDIR)/Makefile
include $(APPDIR)/Makefile


$(OBJDIR)/%.o: %.c
	$(GCC) $(CFLAGS) -o $@ $< $(BASEINC)

$(OBJDIR)/%.o: %.cpp
	$(GPP) $(CFLAGS) -o $@ $< $(BASEINC)

